<template>
  <cs-container :is-back-to-top="true">
    <page-header
      slot="header"
      :loading="loading"
      @submit="handleSubmit"
      ref="header"
    />
    <page-main
      :loading="loading"
      :currentTableData='currentTableData'
      @handleButton="handleButton"
      ref="main"/>
    <page-footer
      slot="footer"
      :loading="loading"
      :current="page.pageNo"
      :size="page.pageSize"
      :total="totalPage"
      @change="handlePaginationChange"/>
  </cs-container>
</template>

<script>
import { normalizadictvalue, DeleteNormaliza } from '@/api/generalization/dictionary'
export default {
  name: 'dictionary',
  data() {
    return {
      loading: false,
      totalPage: 0,
      page: {
        pageNo: 1,
        pageSize: 10,
        keyword: ''
      },
      currentTableData: []
    }
  },
  components: {
    'PageHeader': () => import('./components/PageHeader'),
    'PageMain': () => import('./components/PageMain'),
    'PageFooter': () => import('@/layout/header-aside/components/footer')
  },
  mounted() {
    this.queryNormalizadictvalue(true)
  },
  methods: {
    // 查询列表
    async queryNormalizadictvalue(init) {
      if (init) {
        this.page.pageNo = 1
      }
      const data = await normalizadictvalue(this.page)
      if (data.code === 200) {
        this.currentTableData = data.data.rows
        this.totalPage = data.data.totalRows
      }
    },
    // 删除 DeleteNormaliza
    async deleteNormaliza(parems) {
      const data = await DeleteNormaliza(parems)
      if (data.code === 200) {
        this.queryNormalizadictvalue()
      }
    },
    handleSubmit(val) {
      this.page.keyword = val.keyword
      this.queryNormalizadictvalue(true)
    },
    handleButton(val) {
      if (val.methods === 'delete') {
        this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          const parems = {
            id: val.row.typeId
          }
          this.deleteNormaliza(parems)
        }).catch(() => {
        })
      }
    },
    handlePaginationChange(val) {
      this.page.pageSize = val.size
      this.queryNormalizadictvalue(true)
    }
  }
}
</script>

<style scoped>

</style>
